<template>
  <!-- 店铺管理 -->
  <div class="app-container">
    <el-form class="search-form-new" :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="店铺名称" prop="tenantName">
        <el-input v-model="queryParams.tenantName" placeholder="请输入店铺名称" clearable />
      </el-form-item>

      <el-form-item label="店铺状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="店铺状态" clearable>
          <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item> -->
      <el-form-item class="btns">
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button type="warning" icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button type="success" icon="el-icon-plus" @click="handleAdd">新增</el-button>
      </el-form-item>
    </el-form>

    <div class="table_box">
      <el-table stripe v-loading="loading" :data="roleList">
        <el-table-column label="店铺编号" prop="tenantId" width="90" />
        <el-table-column label="店铺名称" prop="tenantName" width="150" />
        <el-table-column label="店铺LOGO" prop="avatar" width="95">
          <template slot-scope="scope">
            <div v-if="scope.row.avatar">
              <el-image :preview-src-list="[scope.row.avatar]" :src="scope.row.avatar" alt="" style="width:32px;height:32px;cursor: pointer;"></el-image>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="店铺域名" prop="domain" min-width="120" />
        <el-table-column label="虞豆" prop="campNumber" width="80" />
        <el-table-column label="可用余额" prop="availableMoney" width="90" >
          <template slot-scope="scope">
            <div @click="openMoneyDialog(scope.row)" class="link" v-if="scope.row.availableMoney||scope.row.availableMoney==0">
              {{ scope.row.availableMoney }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="保证金状态" prop="marginState" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.marginState==2" type="success">已缴纳</el-tag>
            <el-tag v-else type="success">未缴纳</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="保证金" prop="marginMoney" width="100" />
        <el-table-column label="认证状态" prop="authType" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.authType==2" type="warning">个人认证</el-tag>
            <el-tag v-else-if="scope.row.authType==3" type="success">企业认证</el-tag>
            <el-tag v-else-if="scope.row.authType==6" type="success">企业认证</el-tag>
            <el-tag v-else type="danger">未认证</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" width="80">
          <template slot-scope="scope">
            <div style="color: green;" v-if="scope.row.status === '0'"> 正常</div>
            <div style="color: red;" v-else> 停用</div>
          </template>
        </el-table-column>

         <el-table-column label="是否活跃" align="center" width="80">
          <template slot-scope="scope">
            <div v-if="scope.row.isActive == 1"> 活跃</div>
            <div v-else> 不活跃</div>
          </template>
        </el-table-column>

        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220">
          <template slot-scope="scope">
            <el-button type="edit" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>

            <!-- <el-button type="del" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button> -->
            <el-button type="text" @click="openServerDialog(scope.row.tenantId,scope.row.campNumber)">服务列表</el-button>
            <el-dropdown trigger="click" @command="moreFn($event,scope.row)">
              <span class="el-dropdown-link">
                更多<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="1">增加虞豆</el-dropdown-item>
                <el-dropdown-item command="2">推送配置</el-dropdown-item>
                <el-dropdown-item command="3">七牛云配置</el-dropdown-item>
                <el-dropdown-item command="4">应用商店推广配置</el-dropdown-item>
                <el-dropdown-item command="5">支付宝管理</el-dropdown-item>
                <el-dropdown-item command="6">短信模版配置</el-dropdown-item>
                <el-dropdown-item command="7">卡位短信收费设置</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>

          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    </div>

    <!-- 添加或修改店铺对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="860px" append-to-body>
      <el-form ref="form" :model="form" :inline="true" :rules="rules" label-width="110px">
        <el-form-item label="店铺LOGO" prop="avatar" :class="{ hiddenupload: form.avatar }">
          <el-upload :action="uploadImgUrl" :headers="headers" :file-list="avatarImgList" :show-file-list="true" list-type="picture-card" :limit="1" :on-success="handleAvatarSuccess2" :on-remove="handleAvatarRemove2">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <br />
        <el-form-item label="店铺名称" prop="tenantName">
          <el-input v-model="form.tenantName" placeholder="请输入店铺名称" />
        </el-form-item>
        <el-form-item label="管理员" prop="adminId">
          <virtual-select v-model="form.adminId" :list="allUsers" label="nickName" value="userId" :placeholder="'输入关键字用于搜索用户'" :keeps-params="20" :is-concat="false" :concat-symbol="' || '" :is-multiple="false" :disabled="false" :allow-create="true" />
        </el-form-item><br />

        <!-- <el-form-item label="店铺权重" prop="odr">
          <el-input-number v-model="form.odr" controls-position="right" :min="0" />
        </el-form-item> -->
        <el-form-item label="店铺域名" prop="domain">
          <el-input type="textarea" style="width: 510px;" v-model="form.domain" placeholder="请输入店铺域名" />
        </el-form-item>
        <el-form-item label="短信分享域名" prop="otherDomain">
          <el-input type="text" style="width: 510px;" v-model="form.otherDomain" placeholder="请输入短信分享域名" />
        </el-form-item>
        <el-form-item label="域名备案号" prop="beian">
          <el-input v-model="form.beian" placeholder="域名的工信部备案号" />
        </el-form-item>
        <!-- <el-form-item label="店铺地址" prop="otherShopAddress">
          <el-input v-model="form.otherShopAddress" placeholder="淘宝、PDD等平台店铺地址" />
        </el-form-item> -->
        <!-- <el-form-item label="加价比例" prop="rise">
          <el-input v-model="form.rise" placeholder="请输入加价比例" />
        </el-form-item>
        <el-form-item label="供货商折扣" prop="discountt">
          <el-input v-model="form.discountt" placeholder="请输入供货商折扣" />
        </el-form-item>
        <el-form-item label="销售折扣" prop="supydiscount">
          <el-input v-model="form.supydiscount" placeholder="请输入销售折扣" />
        </el-form-item>
        <el-form-item label="包赔比例" prop="guaranteeRatio">
          <el-input v-model="form.guaranteeRatio" placeholder="请输入包赔比例" />
        </el-form-item>
        <el-form-item label="包赔抽成" prop="guaranteeRoyalty">
          <el-input v-model="form.guaranteeRoyalty" placeholder="请输入包赔抽成" />
        </el-form-item><br /> -->
        <el-form-item label="appId" prop="appId">
          <el-input v-model="form.appId" placeholder="新增时可不填" />
        </el-form-item>
        <el-form-item label="appSecret" prop="appSecret">
          <el-input v-model="form.appSecret" placeholder="新增时可不填" />
        </el-form-item>
        <el-form-item label="最大商品数" prop="goodsMaxnum">
          <el-input v-model="form.goodsMaxnum" placeholder="最大商品数" />
        </el-form-item>
        <el-form-item label="每日克隆数量" prop="goodsCopynum">
          <el-input v-model="form.goodsCopynum" placeholder="每日克隆数量" />
        </el-form-item>
        <el-form-item label="支付中心商户ID" prop="payMerchantId">
          <el-input v-model="form.payMerchantId" placeholder="虞都支付中心商户id" />
        </el-form-item>
        <br />
        <el-form-item label="技术服务费" prop="jsRatio">
          <el-input style="width: 200px;" type="number" v-model="form.jsRatio" placeholder="在线支付技术服务费百分比">
            <span slot="suffix">%</span>
          </el-input>
        </el-form-item>
        <el-form-item label="" prop="">
          <el-button type="primary" plain @click="copyKey">复制秘钥</el-button>
        </el-form-item>
        <br />
        <el-form-item label="推广开户费" prop="linksPrice">
          <el-input style="width: 200px;" type="number" v-model="form.linksPrice" placeholder="该商户推广链接的开户费">

          </el-input>
        </el-form-item>
        <el-form-item label="推广返利" prop="linksPriceRebate">
          <el-input style="width: 200px;" type="number" v-model="form.linksPriceRebate" placeholder="该商户推广链接开户的返利">

          </el-input>
        </el-form-item>
        <br />
         <el-form-item label="回收线索费" prop="backFixedPrice">
          <el-input style="width: 200px;" type="number" v-model.number="form.backFixedPrice" placeholder="该商户回收线索固定值">
             <span slot="suffix">元</span>
          </el-input>
            <i style="margin:0 4px ;" class="el-icon-plus"></i>
           <el-input style="width: 200px;" type="number" v-model.number="form.backRatioPrice"  :min="0" :max="100" :step="0.1" @input="handleRatioInput" placeholder="该商户回收线索百分比">
             <span slot="suffix">%</span>
          </el-input>
        </el-form-item>
        <br />
        
        <!-- <el-form-item label="企业全称" prop="enterpriseName">
          <el-input v-model="form.enterpriseName" placeholder="请输入企业全称" />
        </el-form-item>
        <el-form-item label="纳税人识别号" prop="businessLicenseNumber">
          <el-input v-model="form.businessLicenseNumber" placeholder="请输入纳税人识别号" />
        </el-form-item>

        <el-form-item label="企业微信号" prop="wechatNumber">
          <el-input v-model="form.wechatNumber" placeholder="请输入企业微信号" />
        </el-form-item>
        <el-form-item label="企业支付宝号" prop="alipayNumber">
          <el-input v-model="form.alipayNumber" placeholder="请输入企业支付宝号" />
        </el-form-item> -->
        <el-form-item label="联系人微信" prop="lianxiweixin">
          <el-input v-model="form.lianxiweixin" placeholder="请输入联系人微信" />
        </el-form-item>
        <el-form-item label="联系人手机" prop="lianxishouji">
          <el-input v-model="form.lianxishouji" placeholder="请输入企业支付宝号" />
        </el-form-item>
        <el-form-item label="货源数量限制" prop="huoyuannum">
            <el-input v-model="form.huoyuannum" placeholder="分销网最多能勾选多少个商家" />
          </el-form-item>
        <br />
        <el-form-item label="卡位系统ID" prop="cardUserId">
          <el-input v-model="form.cardUserId" placeholder="请输入卡位系统ID" />
        </el-form-item>
        <el-form-item label="卡位系统UID" prop="cardUserUid">
          <el-input v-model="form.cardUserUid" placeholder="请输入卡位系统UID" />
        </el-form-item>
        <el-form-item label="商家排行" prop="paihang">
          <el-input v-model="form.paihang" placeholder="请输入商家排行" />
        </el-form-item>
        <br />
        <el-form-item label="优质商家">
          <el-radio-group style="width: 202px;" v-model="form.isQuality">
            <el-radio :label="2">是</el-radio>
            <el-radio :label="1">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="出租卡位收虞豆">
          <el-radio-group v-model="form.smsKou">
            <el-radio :label="2">是</el-radio>
            <el-radio :label="1">否</el-radio>
          </el-radio-group>
        </el-form-item>
        
        <el-form-item label="营业执照" prop="businessLicenseImg" :class="{ hiddenupload: form.businessLicenseImg }">
          <el-upload :action="uploadImgUrl" :file-list="businessLicenseImgList" :show-file-list="true" list-type="picture-card" :limit="1" :on-success="handleAvatarSuccess" :on-remove="handleAvatarRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item><br />
        <!-- <el-form-item label="是否显示" prop="isshow">
          <el-radio-group v-model="form.isshow">
            <el-radio label="1">显示</el-radio>
            <el-radio label="2">不显示</el-radio>
          </el-radio-group>
        </el-form-item><br /> -->
        <!-- <el-form-item label="是否监测" prop="moncheck">
          <el-radio-group v-model="form.moncheck">
            <el-radio label="1">监测</el-radio>
            <el-radio label="2">不监测</el-radio>
          </el-radio-group>
        </el-form-item><br /> -->
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.value">{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <br/>
        <el-form-item label="是否活跃">
          <el-radio-group v-model="form.isActive">
            <el-radio :label="1">活跃</el-radio>
            <el-radio :label="2">不活跃</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item label="备注">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">

        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
    <serverListDialog ref="serverListDialog"></serverListDialog>
    <!-- 变更虞豆余额 -->
    <el-dialog :visible.sync="editCampNumberShow" top="300px" width="500px" title="虞豆变动" append-to-body>
      <el-form>
        <h3>店铺：{{changeForm.tenantName}}</h3>
        <h3>当前虞豆余额：{{changeForm.campNumberNow}}</h3>
        <el-form-item label="虞豆变动" prop="campNumber">
          <el-input style="width:270px" type="number" controls-position="right" v-model="changeForm.campNumber" placeholder="正数为增加虞豆，负数为减少虞豆" max="999999999" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">

        <el-button @click="editCampNumberShow = false">取 消</el-button>
        <el-button type="primary" @click="submitEditCampNumberForm">确 定</el-button>
      </div>
    </el-dialog>

    <setPushConfig ref="setPushConfig"></setPushConfig>
    <ZFBmanage ref="ZFBmanage"></ZFBmanage>
    <SMSTemplate ref="SMSTemplate"></SMSTemplate>
    <SMSyudouConfig ref="SMSyudouConfig"></SMSyudouConfig>
    <yueMX ref="yueMX"></yueMX>
  </div>
</template>

<script>
import {
  shopList,
  getShopDetail,
  delShop,
  addShop,
  editShop,
  openSelfShop,
  openApi,
  tenantUpCampNumber,
} from "@/api/system/shopManage";
import supplyConfigApi from "@/api/system/supplyConfig";
import VirtualSelect from "@/components/VirtualSelect.vue";
import serverListDialog from "./serverListDialog.vue";
import setPushConfig from "./setPushConfig.vue";
import ZFBmanage from "./ZFBmanage.vue";
import SMSTemplate from "./SMSTemplate.vue";
import SMSyudouConfig from "./SMSyudouConfig.vue"
import { getToken } from "@/utils/auth";
import yueMX from "./yueMX.vue";
export default {
  name: "TenantManage",
  components: { VirtualSelect, serverListDialog, setPushConfig,ZFBmanage ,SMSTemplate,SMSyudouConfig,yueMX},
  dicts: ["sys_normal_disable"],
  data() {
    return {
      uploadImgUrl: "",
      headers: {},
      businessLicenseImgList: [],
      avatarImgList: [],
      // 遮罩层
      loading: true,

      // 总条数
      total: 0,
      // 店铺表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined,
        tenantName:''
      },
      allUsers: [], //所有用户
      // 表单参数
      form: {
        
      },
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 表单校验
      rules: {
        tenantName: [
          { required: true, message: "店铺名称不能为空", trigger: "blur" },
        ],
        adminId: [
          { required: true, message: "管理员ID不能为空", trigger: "blur" },
        ],
      },
      editCampNumberShow: false,
      currentShop: {},
      changeForm: {},
    };
  },
  created() {
    this.uploadImgUrl = process.env.VUE_APP_BASE_API + "/upload/image";
    this.headers = {
      Authorization: "Bearer " + getToken(),
    };
    // this.headers
    this.getList();
  },
  methods: {
     handleRatioInput(value) {
      if (value === null || value === '') {
        this.form.backRatioPrice = null;
        return;
      }
      
      // 正则过滤：只保留数字和一位小数
      const filtered = Number(value.toString().match(/^\d+(\.\d{0,1})?/)?.[0] || 0);
      
      // 边界值处理（确保在0-100之间）
      this.form.backRatioPrice = Math.min(Math.max(filtered, 0), 100);
    },
    //打开余额明细
    openMoneyDialog(shop){
      this.$refs.yueMX.open(shop.tenantId)
    },
    // 更多操作
    moreFn(e, row) {
      if (e == 1) {
        // 增加虞豆
        this.addYudou(row);
      } else if (e == 2) {
        // 推送配置
        this.openSetPush(row);
      } else if (e == 3) {
        // 七牛云配置
        this.openSetQiniu(row);
      } else if (e == 4) {
        // 应用商店推广配置
        this.openSetAppstore(row);
      }else if (e == 5) {
        // 支付宝管理
        this.openZfbManage(row);
      }else if (e == 6) {
        // 短信模版配置
        this.openSMSModel(row);
      }else if (e ==7) {
        // 短信模版配置
        this.openSMSyudouDialog(row);
      }
    },
    // 打开卡位短信收费设置
    openSMSyudouDialog(row){
      this.$refs.SMSyudouConfig.open(row)
    },
    // 打开短信模板设置
    openSMSModel(row){
      this.$refs.SMSTemplate.open(row)

    },
    // 打开支付宝管理
    openZfbManage(row){
      this.$refs.ZFBmanage.open(row)
    },
    // 一键复制秘钥
    copyKey() {
      let str = `接口地址：https://api.yuduhulian.com \n 接口文档： https://note.youdao.com/s/M3WKl3cb \n appId：${this.form.appId} \n appSecret：${this.form.appSecret} \n  用户id：上传商品的用户编号（开通“供货接口”服务后生效并且必填，商品对接到该用户名下；否则不用填 商品对接到店铺管理员名下。）`;
      this.$copyText(str).then(
        (e) => {
          this.$message({
            type: "success",
            message: "已复制到剪切板！",
          });
        },
        function (e) {}
      );
    },
    // submitEditCampNumberForm 提交虞豆变动
    submitEditCampNumberForm() {
      this.$modal
        .confirm("提交后该店铺会产生一条虞豆变动记录，操作不可撤销，是否继续？")
        .then(() => {
          tenantUpCampNumber(this.changeForm).then((res) => {
            this.editCampNumberShow = false;
            if (res.code == 200) {
              this.getList();
              this.$alert("虞豆变动成功！");
              this.changeForm = {
                tenantId: "",
                campNumberNow: "",
                tenantName: "",
                campNumber: "",
              };
            }
          });
        })
        .catch(() => {});
    },
    // 打开推送配置弹窗
    openSetPush(row) {
      this.$refs.setPushConfig.open(row.tenantId, row.tenantName, "push");
    },
    // 打开七牛云配置
    openSetQiniu(row) {
      this.$refs.setPushConfig.open(row.tenantId, row.tenantName, "qiniu");
    },
    // 打开应用商店推广配置
    openSetAppstore(row) {
      this.$refs.setPushConfig.open(row.tenantId, row.tenantName, "appStore");
    },
    // 打开虞豆变动弹窗
    addYudou(row) {
      this.changeForm = {
        tenantId: row.tenantId,
        campNumberNow: row.campNumber,
        tenantName: row.tenantName,
        campNumber: "",
      };
      this.editCampNumberShow = true;
    },
    // 所有用户
    getAllUserList(val) {
      supplyConfigApi
        .getAllUserList({
          userNewType: 1,
        })
        .then((res) => {
          this.allUsers = res.rows;
        });
    },
    // 店铺LOGO图片移除
    handleAvatarRemove2(response, file) {
      this.form.avatar = "";
      this.avatarImgList = [];
    },
    // 店铺LOGO图片上传成功
    handleAvatarSuccess2(res, file) {
      if (res.code == 200) {
        let url = res.data.filePath;
        let name = res.data.fileName;
        let param = {};
        param.url = url;
        param.name = name;
        this.avatarImgList.push(param);
        this.form.avatar = res.data.filePath;
      }
    },
    // 营业执照图片移除
    handleAvatarRemove(response, file) {
      this.form.businessLicenseImg = "";
      this.businessLicenseImgList = [];
    },
    // 营业执照图片上传成功
    handleAvatarSuccess(res, file) {
      if (res.code == 200) {
        let url = res.data.filePath;
        let name = res.data.fileName;
        let param = {};
        param.url = url;
        param.name = name;
        this.businessLicenseImgList.push(param);
        this.form.businessLicenseImg = res.data.filePath;
      }
    },

    /** 查询店铺列表 */
    getList() {
      this.loading = true;
      shopList(this.queryParams).then((response) => {
        this.roleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 店铺状态修改
    handleStatusChange(row) {
      // let text = row.status === "0" ? "启用" : "停用";
      // this.$modal.confirm('确认要"' + text + '""' + row.roleName + '"店铺吗？').then(function() {
      //   return changeRoleStatus(row.roleId, row.status);
      // }).then(() => {
      //   this.$modal.msgSuccess(text + "成功");
      // }).catch(function() {
      //   row.status = row.status === "0" ? "1" : "0";
      // });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      this.form = {
        isshow: "1",
        moncheck: "2",
        status: "0",
        isActive:1
      };
      this.businessLicenseImgList = [];
      this.avatarImgList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getAllUserList();
      this.open = true;
      this.title = "添加店铺";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.getAllUserList();
      this.reset();
      const tenantId = row.tenantId || this.ids;
      getShopDetail(tenantId).then((response) => {
        this.form = response.data;
        if (this.form.avatar) {
          let obj = {
            url: this.form.avatar,
            name: "0",
          };
          this.avatarImgList.push(obj);
        }
        if (this.form.businessLicenseImg) {
          let obj = {
            url: this.form.businessLicenseImg,
            name: "0",
          };
          this.businessLicenseImgList.push(obj);
        }

        this.open = true;
        this.title = "修改店铺";
      });
    },

    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.linksPriceRebate > this.form.linksPrice) {
            return this.$modal.msgError("推广返利不能大于开户费！");
          }
          if(!this.form.backRatioPrice) {
            this.form.backRatioPrice =0
          }
          if(!this.form.backRatioPrice) {
            this.form.backFixedPrice =0
          }
          if (this.form.tenantId) {
            editShop(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addShop(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 打开服务列表弹窗
    openServerDialog(id, campNumber) {
      this.$refs.serverListDialog.open(id, campNumber);
    },
    /** 开通自营商城 */
    openSelfShop(id) {
      this.$modal
        .confirm('确认为编号为"' + id + '"的店铺开通自营商城吗？')
        .then(() => {
          openSelfShop({
            tenantId: id,
          }).then((res) => {
            this.$message.success(res.msg);
            this.getList();
          });
        })
        .catch(() => {});
    },
    // 开通接口服务
    openApi(id) {
      this.$modal
        .confirm('确认为编号为"' + id + '"的店铺开通接口服务吗？')
        .then(() => {
          openApi({
            tenantId: id,
          }).then((res) => {
            this.$message.success(res.msg);
            this.getList();
          });
        })
        .catch(() => {});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.tenantId || this.ids;
      this.$modal
        .confirm('是否确认删除店铺编号为"' + id + '"的店铺吗？')
        .then(function () {
          return delShop(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="css" scoped>
/deep/ .hiddenupload .el-upload--picture-card {
  display: none;
}
</style>